package com.shop2cn.iapi.sqoptrade.testcase;

import java.math.BigDecimal;
import java.util.Arrays;

import org.junit.*;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.shenqisettlement.parameter.bean.AgentProductBean;
import com.shop2cn.iapi.sqoptrade.parameter.enums.CouponApplianceTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.enums.CouponTypeEnum;
import com.shop2cn.iapi.sqoptrade.parameter.req.CdfDeductCouponBeforePlaceReq;
import com.shop2cn.iapi.sqoptrade.parameter.vo.CouponVo;
import com.shop2cn.iapi.sqoptrade.parameter.vo.OrderVoForCdfCoupon;
import com.shop2cn.iapi.sqoptrade.parameter.vo.ProductVoForCdfCoupon;
import com.shop2cn.iapi.sqoptrade.service.CdfDeductCouponBeforePlaceCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.shenqi.CDFMemberService;
import com.ymttest.business.service.shenqi.DGSQBuildProxyChainCallService;
import com.ymttest.business.service.shenqi.bean.ShenqiUserSet;
import com.ymttest.utils.TestDataManager;

/**
 * 买家确认收货 FreeMaker Template自动生成代码
 */
@TestSuite
@Ignore
public class Ts_CdfDeductCouponBeforePlace {

	private static CdfDeductCouponBeforePlaceReq cdfDeductCouponBeforePlaceReq;
	private static CdfDeductCouponBeforePlaceCall cdfDeductCouponBeforePlaceCall;
	
	private static long cdfMembergoodsOwnerId = ShenqiUserSet.cdfMembergoodsOwnerId;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取下单前扣减大会员电子券金额");
	}

	@Before
	public void caseUp() {

		cdfDeductCouponBeforePlaceReq = new CdfDeductCouponBeforePlaceReq();
		cdfDeductCouponBeforePlaceCall = new CdfDeductCouponBeforePlaceCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(cdfDeductCouponBeforePlaceCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	public ProductVoForCdfCoupon buildStandardProduct() {

		ProductVoForCdfCoupon productVo = new ProductVoForCdfCoupon();

		productVo.setCatalogId("catalogId" + TestDataManager.randomStr(5));
		productVo.setProductId("productId" + TestDataManager.randomStr(5));
		productVo.setPrice(new BigDecimal("100.00"));
		productVo.setProductNum(1);
		productVo.setSubProduct(false);
		productVo.setSkuId("skuId" + TestDataManager.randomStr(5));

		return productVo;
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CdfDeductCouponBeforePlace_001() {
		Logger.start(false, "一个订单，一个商品，大会员满减券");
		try {
			
			// 领取cdf优惠券
			CDFMemberService.getCdfCoupon(CouponTypeEnum.FULL_REDUCTION_COUPON
					.getCode(), 1, 26080783L);

			CouponVo couponVo = new CouponVo();

			couponVo.setApplianceType(CouponApplianceTypeEnum.ALL);
			couponVo.setCouponSource(1);
			couponVo.setCouponType(CouponTypeEnum.FULL_REDUCTION_COUPON
					.getCode());
			couponVo.setCouponCode(CDFMemberService.getLatestUnuseCdfCoupon(
					26080783L, cdfMembergoodsOwnerId));
			
			cdfDeductCouponBeforePlaceReq.setSellerId(cdfMembergoodsOwnerId);
			cdfDeductCouponBeforePlaceReq.setUserId(26080783L);
			cdfDeductCouponBeforePlaceReq.setCouponVo(couponVo);
			
			OrderVoForCdfCoupon orderVo = new OrderVoForCdfCoupon();
			
			ProductVoForCdfCoupon productVo = buildStandardProduct();
			
			orderVo.setProductVoList(Arrays.asList(productVo));
			
			cdfDeductCouponBeforePlaceReq.setOrderVoList(Arrays.asList(orderVo));
			
			cdfDeductCouponBeforePlaceCall
					.setData(cdfDeductCouponBeforePlaceReq);
			cdfDeductCouponBeforePlaceCall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CdfDeductCouponBeforePlace_002() {
		Logger.start(false, "一个订单，多个商品，大会员满折券");
		try {
			
			// 领取cdf优惠券
			CDFMemberService.getCdfCoupon(CouponTypeEnum.CASH_COUPON
					.getCode(), 1, 26080783L);

			CouponVo couponVo = new CouponVo();

			couponVo.setApplianceType(CouponApplianceTypeEnum.ALL);
			couponVo.setCouponSource(1);
			couponVo.setCouponType(CouponTypeEnum.CASH_COUPON
					.getCode());
			couponVo.setCouponCode(CDFMemberService.getLatestUnuseCdfCoupon(
					26080783L, cdfMembergoodsOwnerId));
			
			cdfDeductCouponBeforePlaceReq.setSellerId(cdfMembergoodsOwnerId);
			cdfDeductCouponBeforePlaceReq.setUserId(26080783L);
			cdfDeductCouponBeforePlaceReq.setCouponVo(couponVo);
			
			OrderVoForCdfCoupon orderVo = new OrderVoForCdfCoupon();
			
			ProductVoForCdfCoupon productVo1 = buildStandardProduct();
//			ProductVoForCdfCoupon productVo2 = buildStandardProduct();
			
			productVo1.setPrice(new BigDecimal("23.19"));
			
//			orderVo.setProductVoList(Arrays.asList(productVo1, productVo2));
			orderVo.setProductVoList(Arrays.asList(productVo1));
			
			cdfDeductCouponBeforePlaceReq.setOrderVoList(Arrays.asList(orderVo));
			
			cdfDeductCouponBeforePlaceCall
					.setData(cdfDeductCouponBeforePlaceReq);
			cdfDeductCouponBeforePlaceCall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CdfDeductCouponBeforePlace_003() {
		Logger.start(false, "多个订单，多个商品，大会员满折券");
		try {
			
			// 领取cdf优惠券
			CDFMemberService.getCdfCoupon(CouponTypeEnum.CASH_COUPON
					.getCode(), 1, 26080783L);

			CouponVo couponVo = new CouponVo();

			couponVo.setApplianceType(CouponApplianceTypeEnum.ALL);
			couponVo.setCouponSource(1);
			couponVo.setCouponType(CouponTypeEnum.CASH_COUPON
					.getCode());
			couponVo.setCouponCode(CDFMemberService.getLatestUnuseCdfCoupon(
					26080783L, cdfMembergoodsOwnerId));
			
			cdfDeductCouponBeforePlaceReq.setSellerId(cdfMembergoodsOwnerId);
			cdfDeductCouponBeforePlaceReq.setUserId(26080783L);
			cdfDeductCouponBeforePlaceReq.setCouponVo(couponVo);
			
			OrderVoForCdfCoupon orderVo1 = new OrderVoForCdfCoupon();
			
			ProductVoForCdfCoupon productVo1 = buildStandardProduct();
			ProductVoForCdfCoupon productVo2 = buildStandardProduct();
			
			orderVo1.setProductVoList(Arrays.asList(productVo1, productVo2));
			
			OrderVoForCdfCoupon orderVo2 = new OrderVoForCdfCoupon();
			
			ProductVoForCdfCoupon productVo3 = buildStandardProduct();
			
			orderVo2.setProductVoList(Arrays.asList(productVo3));
			
			cdfDeductCouponBeforePlaceReq.setOrderVoList(Arrays.asList(orderVo1, orderVo2));
			
			cdfDeductCouponBeforePlaceCall
					.setData(cdfDeductCouponBeforePlaceReq);
			cdfDeductCouponBeforePlaceCall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CdfDeductCouponBeforePlace_004() {
		Logger.start(false, "一个订单，一个组合商品，大会员满减券");
		try {
			
			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createComposeProductProxychain(
							(int) cdfMembergoodsOwnerId, false, true);
			
			// 领取cdf优惠券
			CDFMemberService.getCdfCoupon(CouponTypeEnum.FULL_REDUCTION_COUPON
					.getCode(), 1, 26080783L);

			CouponVo couponVo = new CouponVo();

			couponVo.setApplianceType(CouponApplianceTypeEnum.ALL);
			couponVo.setCouponSource(1);
			couponVo.setCouponType(CouponTypeEnum.FULL_REDUCTION_COUPON
					.getCode());
			couponVo.setCouponCode(CDFMemberService.getLatestUnuseCdfCoupon(
					26080783L, cdfMembergoodsOwnerId));
			
			cdfDeductCouponBeforePlaceReq.setSellerId(cdfMembergoodsOwnerId);
			cdfDeductCouponBeforePlaceReq.setUserId(26080783L);
			cdfDeductCouponBeforePlaceReq.setCouponVo(couponVo);
			
			OrderVoForCdfCoupon orderVo = new OrderVoForCdfCoupon();
			
			ProductVoForCdfCoupon productVo = buildStandardProduct();
			
			productVo.setProductId(productBean.getProductId());
			productVo.setCatalogId(productBean.getCatalogList().get(0));
			
			productVo.setSubProduct(true);
			
			orderVo.setProductVoList(Arrays.asList(productVo));
			
			cdfDeductCouponBeforePlaceReq.setOrderVoList(Arrays.asList(orderVo));
			
			cdfDeductCouponBeforePlaceCall
					.setData(cdfDeductCouponBeforePlaceReq);
			cdfDeductCouponBeforePlaceCall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
